<?php
namespace App\Service\Item;

use App\Service\BaseService as Service;
use Illuminate\Support\Facades\DB;

class BaseService extends Service
{
    //基础服务

    //返回参数
    public function xmback($code = 0, $msg = '', $data = [], $total = 0)
    {
        $msg = $msg ? $msg : 'success';
        return array('code' => $code, 'msg' => $msg, 'data' => $data, 'total' => $total);
    }

    /**
     * 连接数据库
     * @param string $db 表名
     * @param array $ws 查询条件【key=>val】
     */
    public function xmConn($db, $ws=[])
    {
        $db = DB::connection($this->dbxm)->table($db);
        if (!empty($ws)) {
            foreach ($ws as $k => $v) {
                $db = $db->where($k, $v);
            }
        }
        return $db;
    }
}